package com.design3.graduatethesissys.controller;

import java.util.List;
import java.util.Map;

import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.design3.graduatethesissys.service.SubjectService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Controller
@RequestMapping("/Student/subject")
public class SubjectController {
	@Autowired
	SubjectService subjectService;
//	@ResponseBody
//	@RequestMapping("/select")
//	public List<Map<String, Object>> subjectSearch(@RequestParam("sbj_status") String sbj_status) {
//		return subjectService.subjectSearch(sbj_status);
//	}
	
	@ResponseBody
	@RequestMapping("/select")
	public List<Map<String, Object>> subjectSearch(@RequestParam("page") int page,
			@RequestParam("sbj_status") String sbj_status,
			@RequestParam(value="sbj_name",required=false) String sbj_name,
			@RequestParam(value="teh_name",required=false) String teh_name) {
		PageHelper.startPage(page, 10);
		List<Map<String, Object>> subjectList = subjectService.subjectSearch(sbj_status, sbj_name, teh_name);
		PageInfo<Map<String, Object>> personPageInfo = new PageInfo<>(subjectList);	
		List<Map<String, Object>> pageList = personPageInfo.getList();
		return pageList;
	}

	// 后端分页样例
	@ResponseBody
	@RequestMapping("/list")
	public List<Map<String, Object>> subjectlist(@RequestParam("page") int page,
			@RequestParam("sbj_status") String sbj_status) {
//		System.out.println(page);
		PageHelper.startPage((page - 1) * 10 + 1, 10);
		List<Map<String, Object>> subjectList = subjectService.subjectSearch(sbj_status,"","");
		// 得到分页的结果对象
		PageInfo<Map<String, Object>> personPageInfo = new PageInfo<>(subjectList);
		// 得到分页中的person条目对象
		List<Map<String, Object>> pageList = personPageInfo.getList();
		return pageList;
	}

	/*@ResponseBody
	@RequestMapping("/download")
	public String download(HttpServletResponse response) {
		// 文件路径
		 Boolean result = FileUtil.download(response,"2016220203022","初期报告");
		 if(result){
		 	return "success";
		 }else {
		 	return "fail";
		 }
	}*/

	@RequestMapping("/h")
	public String text() {
		return "/Student/StudentChat";
	}
	/*@ResponseBody
	@RequestMapping("/upload")
	public String upload(HttpServletRequest request, HttpServletResponse response) throws IOException {
		// 文件路径
		String strUrl = "G:\\新建 DOC 文档.doc";
		File file = new File(strUrl);
		InputStream inputStream = new FileInputStream(file);
		MultipartFile multipartFile = new MockMultipartFile(file.getName(), inputStream);
		return  FileUtil.upload(multipartFile,"2016220203022","初期报告");
	}*/
}
